#ifndef HOT_HPP  
#define HOT_HPP 
#include"data.hpp"
#include"util.hpp"
#include<unistd.h>
#include"myconfig.hpp"
extern cloud:: DataManger *_data;

namespace cloud{
 class HotManger{
   private:
   std::string _back_dir;
   std::string _pack_dir;
   std::string _pack_suffix;
   int _hot_time;
   private:
   bool HotJudge(const std::string &filename){

    FileUtil fu(filename);
    time_t last_atime=fu.LastATime();
    time_t cur_time=time(nullptr);
    if(cur_time-last_atime>_hot_time){

      return true;

    }
      return false;





   }
   public:
   HotManger()
   {
   Config *config=Config::GetInstance();
   _back_dir=config->GetBackDir();
   _pack_dir=config->GetPackDir();
   _pack_suffix=config->GetpackFileSuffix();
   _hot_time=config->GetHotTime();
   FileUtil tmp1(_back_dir);
   FileUtil tmp2(_pack_dir);
   tmp1.CreateDirectory();
   tmp2.CreateDirectory();

   
   }
   bool RunModule()
   {
     while(1)
     {   //遍历备份目录，获取所有文件名
      FileUtil fu(_back_dir);
      std::vector<std::string>array;
      fu.ScanDirectory(&array);

      //遍历判断文件是否是非热点文件
      for(auto &a:array)
      {
           if(HotJudge(a)==false){
               continue;


           }
       
       BackupInfo bi;
       if(_data->GetOneByRealPath(a,&bi)==false){
       

          bi.NewBackupInfo(a);


       }


       //对非热点文件进行压缩
       FileUtil tmp(a);
       tmp.Compress(bi.pack_path);
       //删除源文件，修改备份信息
       tmp.Remove();
       bi.pack_flag=true;
       _data->Update(bi);


      }
      usleep(1000);
      }


     return true;
 
   }



 };









}


























#endif